package com.chancein.cloud.ocr.process.util;

import org.apache.commons.lang3.math.NumberUtils;

/**
 * ocr 文件处理工具
 *
 * @author: LiaoZiHao
 * @date: 2023/8/8 18:47
 * Copyright © 2022 Hundsun Technologies Inc. All Rights Reserved
 */
public class FileUtils {
    public static String getNetworkFileExt(String path) {
        String ext = "";
        if (path != null) {
            int index = path.lastIndexOf(".");
            if (index == -1) {
                ext = "";
            } else {
                ext = path.substring(index + 1);
                if (!ext.contains("/") && !ext.contains("\\")) {
                    index = ext.lastIndexOf("?");
                    if (index != -1) {
                        ext = ext.substring(0, index);
                    }
                } else {
                    ext = "";
                }
            }
        }

        if (ext.length() > 10 || NumberUtils.isDigits(ext)) {
            ext = "";
        }

        return ext.toUpperCase();
    }
}
